// pages/fpReserve/fpReserve.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imageRoot: app.globalData.imageRoot,
    show: false,
    value: 5,
    step_list: [{
        id: 1,
        name: '发起服务',
        img: '',
        time: ''
      },
      {
        id: 2,
        name: '获取需求',
        img: '',
        time: ''
      },
      {
        id: 3,
        name: '线上邀约',
        img: '',
        time: ''
      },
      {
        id: 4,
        name: '邀约面谈',
        img: '',
        time: ''
      },
      {
        id: 5,
        name: '准备签约',
        img: '',
        time: ''
      },
    ],
    active: 0,
    btnText: '下一步',
    show: false,
    select: [{
      name: '服务有礼',
      index: 0
    }, {
      name: '专业讲师',
      index: 0
    }, {
      name: '最佳指导',
      index: 0
    }],
    list: {},
    Model: false,
    user: {},
    status: null
  },
  stay(e) {
    var that = this;
    var value = e.detail.value;
    console.log(e.detail.value);
    var data = {
      remark: value
    }
    var step_list = that.data.step_list;
    console.log(that.data.list)
    switch (Number(that.data.type)) {
      case 1:
        getApp().ports.fpgdzt({
          data: data,
          id: that.data.list.id
        }).then((res) => {
          var res = res.data;
          that.user(res.marketer)
          res.time = app.timeFormat(res.createTime)
          step_list[0].time = app.timeFormat(res.createTime, false, true)
          step_list[1].time = app.timeFormat(res.getDemandTime, false, true)
          step_list[2].time = app.timeFormat(res.olInviteTime, false, true)
          step_list[3].time = app.timeFormat(res.interviewTime, false, true)
          step_list[4].time = app.timeFormat(res.beforeSignTime, false, true)
          that.setData({
            list: res,
            step_list: step_list
          })
        }).catch(() => {
          console.error('出啥错了？');
        });
        break;
      case 2:
        getApp().ports.zkgdzt({
          data: data,
          id: that.data.list.id
        }).then((res) => {
          var res = res.data;
          that.user(res.marketer)
          res.time = app.timeFormat(res.createTime, true);
          step_list[0].time = app.timeFormat(res.createTime, false, true)
          step_list[1].time = app.timeFormat(res.getDemandTime, false, true)
          step_list[2].time = app.timeFormat(res.olInviteTime, false, true)
          step_list[3].time = app.timeFormat(res.interviewTime, false, true)
          step_list[4].time = app.timeFormat(res.beforeSignTime, false, true)
          that.setData({
            list: res,
            step_list: step_list
          })
        }).catch(() => {
          console.error('出啥错了？');
        });
        break;
      case 4:
        getApp().ports.jdgdzt({
          data: data,
          id: that.data.list.id
        }).then((res) => {
          var res = res.data;
          that.user(res.marketer)
          res.time = app.timeFormat(res.createTime, true);
          step_list[0].time = app.timeFormat(res.createTime, false, true)
          step_list[1].time = app.timeFormat(res.getDemandTime, false, true)
          step_list[2].time = app.timeFormat(res.olInviteTime, false, true)
          step_list[3].time = app.timeFormat(res.interviewTime, false, true)
          step_list[4].time = app.timeFormat(res.finishTime, false, true)

          res.tags = [{
            name: res.investigationOrder.foreclosedHouse.builtUpAreaSquareCentimeter + '㎡'
          }, {
            name: res.investigationOrder.rate + '折'
          }, {
            name: res.investigationOrder.foreclosedHouse.status
          }]
          
          that.setData({
            list: res,
            step_list: step_list
          })
        }).catch(() => {
          console.error('出啥错了？');
        });
        break;
    }
  },
  api(data) {
    var that = this;
    var statuss = ['待审核', '待上架', '出售中', '已出售'];
    var type = that.data.type;
    var data = data;
    var step_list = that.data.step_list;
    if (type == 1) { //优选
      data.foreclosedHouseBookingorderId = that.data.id
      getApp().ports.fpgd({ //优选
        data: data
      }).then((res) => {
        console.log(that.data.user, '=====');
        var res = res.data;
        res.time = app.timeFormat(res.createTime, true)
        step_list[0].time = app.timeFormat(res.createTime, false, true)
        step_list[1].time = app.timeFormat(res.getDemandTime, false, true)
        step_list[2].time = app.timeFormat(res.olInviteTime, false, true)
        step_list[3].time = app.timeFormat(res.interviewTime, false, true)
        step_list[4].time = app.timeFormat(res.beforeSignTime, false, true)
        res.foreclosedHouseBookingorder.foreclosedHouse.stTime = app.timeFormat(res.foreclosedHouseBookingorder.foreclosedHouse.startTime)
        // res.foreclosed_house_bookingorder.foreclosedHouse.status = statuss[res.foreclosed_house_bookingorder.foreclosedHouse.status]
        
        res.foreclosedHouseBookingorder.foreclosedHouse.marketPriceYuan = Math.floor((res.foreclosedHouseBookingorder.foreclosedHouse.marketPriceYuan / 10000));
        res.foreclosedHouseBookingorder.foreclosedHouse.priceYuan = Math.floor((res.foreclosedHouseBookingorder.foreclosedHouse.priceYuan / 10000));
        switch (res.foreclosedHouseBookingorder.foreclosedHouse.stage) {
          case '变卖':
            res.foreclosedHouseBookingorder.foreclosedHouse.stage = '秒杀'
            break;
          case '一拍':
            res.foreclosedHouseBookingorder.foreclosedHouse.stage = '一轮'
            break;
          case '二拍':
            res.foreclosedHouseBookingorder.foreclosedHouse.stage = '二轮'
            break;
        }
        switch (res.foreclosedHouseBookingorder.foreclosedHouse.status) {
          case '拍卖中':
            res.foreclosedHouseBookingorder.foreclosedHouse.status = '进行中'
            break;
          case '已流拍':
            res.foreclosedHouseBookingorder.foreclosedHouse.status = '已结束'
            break;
        }
        res.foreclosedHouseBookingorder.foreclosedHouse.tags = [{
          name: res.foreclosedHouseBookingorder.foreclosedHouse.builtUpAreaSquareCentimeter + '㎡'
        }, {
          name: res.foreclosedHouseBookingorder.rate + '折'
        }, {
          name: res.foreclosedHouseBookingorder.foreclosedHouse.status
        }]
        that.user(res.marketer)
        console.log(res, '成功');
        that.setData({
          list: res,
          typeId: res.foreclosedHouseBookingorder.foreclosedHouseId,
          client: that.data.user.client,
          step_list: step_list,
          house: res.foreclosedHouseBookingorder.foreclosedHouse,
          finished: 0
        })
        that.recommend(that.data.user.client)
        that.history()
      }).catch(() => {
        console.error('出啥错了？');
      });
    } else if (type == 2) { //折扣
      data.discountHouseBookingorderId = that.data.id
      console.log(data)
      getApp().ports.zkgd({
        data: data
      }).then((res) => {
        var res = res.data;
        that.user(res.marketer)
        console.log(res, '成功折扣');
        res.time = app.timeFormat(res.createTime, true)
        res.discountHouseBookingorder.discountHouse.stTime = app.timeFormat(res.discountHouseBookingorder.discountHouse.uploadTime)
        // res.discountHouseBookingorder.discountHouse.marketPriceYuan = Math.floor((res.discountHouseBookingorder.discountHouse.marketPriceYuan / 10000));
        // res.discountHouseBookingorder.discountHouse.priceYuan = Math.floor((res.discountHouseBookingorder.discountHouse.priceYuan / 10000));
        res.discountHouseBookingorder.discountHouse.status = statuss[res.discountHouseBookingorder.discountHouse.status]
        res.discountHouseBookingorder.discountHouse.banner = that.data.imageRoot + res.discountHouseBookingorder.discountHouse.banner;

        if (res.discountHouseBookingorder.discountHouse.tagsstr) {
          let tags = [];
          res.discountHouseBookingorder.discountHouse.tagsstr.split(",").forEach(item => {
            tags.push({name: item})
          })
          res.tags = tags;
        }
        // if (res.createTime) {
        //   step_list[0].time = app.timeFormat(res.createTime, false, true)
        // }
        step_list[0].time = app.timeFormat(res.createTime, false, true)
        step_list[1].time = app.timeFormat(res.getDemandTime, false, true)
        step_list[2].time = app.timeFormat(res.olInviteTime, false, true)
        step_list[3].time = app.timeFormat(res.interviewTime, false, true)
        step_list[4].time = app.timeFormat(res.beforeSignTime, false, true)
        that.setData({
          list: res,
          typeId: res.discountHouseBookingorder.discountHouse.id,
          client: that.data.user.client,
          step_list: that.data.step_list,
          house: res.discountHouseBookingorder.discountHouse,
          finished: 0
        })
        that.recommend(that.data.user.client)
        that.history()
      }).catch(() => {
        console.error('出啥错了？');
      });
    } else if (type == 4) { //尽调
      data.investigationOrderId = that.data.id
      getApp().ports.jdgd({
        data: data
      }).then((res) => {
        var res = res.data;
        that.user(res.marketer)
        console.log(res, '成功');
        res.time = app.timeFormat(res.createTime, true)
        res.investigationOrder.foreclosedHouse.stTime = app.timeFormat(res.investigationOrder.foreclosedHouse.startTime)
        step_list[0].time = app.timeFormat(res.createTime, false, true)
        step_list[1].time = app.timeFormat(res.getDemandTime, false, true)
        step_list[2].time = app.timeFormat(res.olInviteTime, false, true)
        step_list[3].time = app.timeFormat(res.interviewTime, false, true)
        step_list[4].time = app.timeFormat(res.beforeSignTime, false, true)
        res.investigationOrder.foreclosedHouse.marketPriceYuan = Math.floor((res.investigationOrder.foreclosedHouse.marketPriceYuan / 10000));
        res.investigationOrder.foreclosedHouse.priceYuan = Math.floor((res.investigationOrder.foreclosedHouse.priceYuan / 10000));
        res.tags = [{
          name: res.investigationOrder.foreclosedHouse.builtUpAreaSquareCentimeter + '㎡'
        }, {
          name: res.investigationOrder.rate + '折'
        }, {
          name: res.investigationOrder.foreclosedHouse.status
        }]
        console.log(res)
        that.setData({
          list: res,
          step_list: that.data.step_list,
          client: res.investigationOrder.client,
          house: res.investigationOrder.foreclosedHouse
        })
        that.recommend(that.data.user.client)
        that.history()
      }).catch(() => {
        console.error('出啥错了？');
      });
    }

  },
  user(info) {
    var that = this;
    getApp().ports.yhxx({
      id: info
    }).then((res) => {
      var list = that.data.list;
      console.log(res)
      var res = res.data;
      list.img = res.avatarUrl;
      list.name = res.nickname;
      list.phone = res.phone;
      that.setData({
        list: list
      })
    }).catch(() => {
      console.error('出啥错了？');
    });
  },
  recommend(id) {
    var that = this;
    app.ports.api40({
      data: {pk: id}
    }).then((res) => {
      that.data.comUser = [];
      that.data.comUser[1] = {name: res.data.first.nickname};
      that.data.comUser[2] = {name: res.data.second.nickname};
      that.setData({
        comUser: that.data.comUser
      })
    }).catch(() => {
      console.error("获取邀请关系报错了！")
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var titles = ['', '优选预约跟单', '折扣预约跟单', '放盘预约跟单', '尽调预约跟单', '好房预约跟单', '增值预约跟单']
    wx.setNavigationBarTitle({
      title: titles[Number(options.type)]
    })
    // console.log("options=====", options);
    that.setData({
      type: options.type,
      user: JSON.parse(decodeURIComponent(options.user)),
    })
    if (options.typeId) {
      that.yyxq(options.typeId)
      that.setData({
        pj: true
      })
    } else {
      var data = {}
      that.setData({
        id: options.id
      })
      that.api(data)
    }
    // that.history()
  },
  yyxq(typeId) {
    var that = this;
    var step_list = that.data.step_list;
    var type = Number(that.data.type);
    switch (type) {
      case 1:
        getApp().ports.fpgdxq({ //优选
          id: typeId
        }).then((res) => {
          var res = res.data;
          res.time = app.timeFormat(res.createTime, true)
          step_list[0].time = app.timeFormat(res.createTime, false, true)
          step_list[1].time = app.timeFormat(res.getDemandTime, false, true)
          step_list[2].time = app.timeFormat(res.olInviteTime, false, true)
          step_list[3].time = app.timeFormat(res.interviewTime, false, true)
          step_list[4].time = app.timeFormat(res.beforeSignTime, false, true)
          res.foreclosedHouseBookingorder.foreclosedHouse.stTime = app.timeFormat(res.foreclosedHouseBookingorder.foreclosedHouse.startTime)
          res.foreclosedHouseBookingorder.foreclosedHouse.marketPriceYuan = Math.floor((res.foreclosedHouseBookingorder.foreclosedHouse.marketPriceYuan / 10000));
          res.foreclosedHouseBookingorder.foreclosedHouse.priceYuan = Math.floor((res.foreclosedHouseBookingorder.foreclosedHouse.priceYuan / 10000));
          res.comment = res.foreclosedHouseBookingorder.comment
          res.rate = res.foreclosedHouseBookingorder.rate
          if (res.stage == 2) {
            that.setData({
              historyShow: true
            })
          }
          switch (res.foreclosedHouseBookingorder.foreclosedHouse.stage) {
            case '变卖':
              res.foreclosedHouseBookingorder.foreclosedHouse.stage = '秒杀'
              break;
            case '一拍':
              res.foreclosedHouseBookingorder.foreclosedHouse.stage = '一轮'
              break;
            case '二拍':
              res.foreclosedHouseBookingorder.foreclosedHouse.stage = '二轮'
              break;
          }
          switch (res.foreclosedHouseBookingorder.foreclosedHouse.status) {
            case '拍卖中':
              res.foreclosedHouseBookingorder.foreclosedHouse.status = '进行中'
              break;
            case '已流拍':
              res.foreclosedHouseBookingorder.foreclosedHouse.status = '已结束'
              break;
          }
          res.foreclosedHouseBookingorder.foreclosedHouse.tags = [{
            name: res.foreclosedHouseBookingorder.foreclosedHouse.builtUpAreaSquareCentimeter + '㎡'
          }, {
            name: res.foreclosedHouseBookingorder.foreclosedHouse.discountRate + '折'
          }, {
            name: res.foreclosedHouseBookingorder.foreclosedHouse.status
          }]
          if (res.foreclosedHouseBookingorder.finished == 1) that.data.btnText = '订单待评价'
          that.user(res.marketer)
          that.recommend(that.data.user.client)

          that.setData({
            list: res,
            client: that.data.user.client,
            house: res.foreclosedHouseBookingorder.foreclosedHouse,
            step_list: step_list,
            user: that.data.user,
            typeId: res.foreclosedHouseBookingorder.foreclosedHouse.id,
            btnText: that.data.btnText,
            finished: res.foreclosedHouseBookingorder.finished
          })
          that.history()
        }).catch(() => {
          console.error('出啥错了？');
        });
        break;
      case 2:
        getApp().ports.zkgdxq({ //折扣
          id: typeId
        }).then((res) => {
          var res = res.data;
          var statuss = ['待审核', '待上架', '出售中', '已出售'];
          res.time = app.timeFormat(res.createTime, true)
          step_list[0].time = app.timeFormat(res.createTime, false, true)
          step_list[1].time = app.timeFormat(res.getDemandTime, false, true)
          step_list[2].time = app.timeFormat(res.olInviteTime, false, true)
          step_list[3].time = app.timeFormat(res.interviewTime, false, true)
          step_list[4].time = app.timeFormat(res.beforeSignTime, false, true)
          res.discountHouseBookingorder.discountHouse.stTime = app.timeFormat(res.discountHouseBookingorder.discountHouse.uploadTime)
          // res.discountHouseBookingorder.discountHouse.marketPriceYuan = Math.floor((res.discountHouseBookingorder.discountHouse.marketPriceYuan / 10000));
          // res.discountHouseBookingorder.discountHouse.priceYuan = Math.floor((res.discountHouseBookingorder.discountHouse.priceYuan / 10000));
          // res.discountHouseBookingorder.discountHouse.status = statuss[res.discountHouseBookingorder.discountHouse.status]
          res.discountHouseBookingorder.discountHouse.status = statuss[res.discountHouseBookingorder.discountHouse.status]
          if (res.discountHouseBookingorder.finished == 1) that.data.btnText = '订单待评价'
          res.comment = res.discountHouseBookingorder.comment
          res.rate = res.discountHouseBookingorder.rate
          that.user(res.marketer)
          if (res.stage == 2) {
            that.setData({
              historyShow: true
            })
          }
          that.setData({
            list: res,
            client: that.data.user.client,
            house: res.discountHouseBookingorder.discountHouse,
            step_list: step_list,
            user: that.data.user,
            typeId: res.discountHouseBookingorder.discountHouse.id,
            btnText: that.data.btnText,
            finished: res.discountHouseBookingorder.finished
          })
          that.recommend(that.data.user.client)
          that.history()
        }).catch(() => {
          console.error('出啥错了？');
        });
        break;
      case 4:
        getApp().ports.jdgdxq({ //尽调
          id: typeId
        }).then((res) => {
          var res = res.data;
          res.time = app.timeFormat(res.createTime, true)
          step_list[0].time = app.timeFormat(res.createTime, false, true)
          step_list[1].time = app.timeFormat(res.getDemandTime, false, true)
          step_list[2].time = app.timeFormat(res.olInviteTime, false, true)
          step_list[3].time = app.timeFormat(res.interviewTime, false, true)
          step_list[4].time = app.timeFormat(res.finishTime, false, true)
          res.investigationOrder.foreclosedHouse.stTime = app.timeFormat(res.investigationOrder.foreclosedHouse.startTime)
          res.investigationOrder.foreclosedHouse.marketPriceYuan = Math.floor((res.investigationOrder.foreclosedHouse.marketPriceYuan / 10000));
          res.investigationOrder.foreclosedHouse.priceYuan = Math.floor((res.investigationOrder.foreclosedHouse.priceYuan / 10000));
          res.tags = [{
            name: res.investigationOrder.foreclosedHouse.builtUpAreaSquareCentimeter + '㎡'
          }, {
            name: res.investigationOrder.rate + '折'
          }, {
            name: res.investigationOrder.foreclosedHouse.status
          }]
          if (res.stage == 2) {
            that.setData({
              historyShow: true
            })
          }
          if (res.stage == 5) that.data.btnText = '订单待评价';
          res.comment = res.investigationOrder.comment
          res.rate = res.investigationOrder.rate
          that.user(res.marketer)
          that.setData({
            list: res,
            client: that.data.user.client,
            house: res.investigationOrder.foreclosedHouse,
            step_list: step_list,
            user: that.data.user,
            typeId: res.investigationOrderId,
            btnText: that.data.btnText
          })
          that.recommend(that.data.user.client)
          that.history()
        }).catch(() => {
          console.error('出啥错了？');
        });
        break;
    }

  },
  history() {
    var that = this;
    var listId = [];
    var houses = [];
    app.ports.userHistory({
      id: that.data.client
    }).then(res => {
      res.data.results.forEach(item => {
        var status = item.houseCategory == 1 ? 0 : 1;
        item.url = '../details/details?id=' + item.houseId + '&status='+status
      })
      that.setData({
        history: res.data
      })
      // for (var i = 0; i < res.data.houses.buckets.length; i++) {
      //   console.log(res.data.houses.buckets[i].latest_access_logs.hits.hits[0]._source)
      //   listId.push(res.data.houses.buckets[i].latest_access_logs.hits.hits[0]._source.house_id)
      //   houses.push(res.data.houses.buckets[i].latest_access_logs.hits.hits[0])
      // }

      // app.ports.gethouses({
      //   data: listId
      // }).then(obj => {
      //   var obj = obj.data;
      //   for (let i = 0; i < obj.results.length; i++) {
      //     obj.results[i].house_category = '折扣'
      //     for (var j = 0; j < houses.length; j++) {
      //       if (obj.results[i].id == res.data.houses.buckets[j].latest_access_logs.hits.hits[0]._source.house_id) {
      //         obj.results[i].browseDate = app.timeFormat(res.data.houses.buckets[j].latest_access_logs.hits.hits[0]._source.access_time, true)
      //         obj.results[i].browseTime = res.data.houses.buckets[j].latest_access_logs.hits.hits[0]._source.access_interval_seconds

      //         // obj.results[i].type = res.data.houses.buckets[j].latest_access_logs.hits.hits[0]._source.house_category
      //       }
      //     }
      //     if (obj.results[i].type == 1) {
      //       obj.results[i].house_category = '优选'
      //       obj.results[i].tags = [{
      //         name: obj.results[i].builtUpAreaSquareCentimeter + '㎡'
      //       }, {
      //         name: obj.results[i].discount_rate + '折'
      //       }, {
      //         name: obj.results[i].stage
      //       }]
      //       obj.results[i].marketPriceYuan = Math.floor((obj.results[i].marketPriceYuan / 10000));
      //       obj.results[i].priceYuan = Math.floor((obj.results[i].priceYuan / 10000));
      //       obj.results[i].time = app.timeFormat(obj.results[i].startTime) + '-' + app.timeFormat(obj.results[i].end_time)
      //     } else {
      //       obj.results[i].time = app.timeFormat(obj.results[i].uploadTime)
      //     }
      //     obj.results[i].url = '../details/details?id=' + obj.results[i].id
      //   }
      //   that.setData({
      //     history: obj
      //   })
      // }).catch(() => {
      //   console.error('浏览记录列表')
      // })
    }).catch(() => {
      console.error('浏览记录列表')
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    var that = this;
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

 
  step(e) {
    var that = this;
    if (e.detail == 1) {
      that.setData({
        active: e.detail
      })
    }
  },
  choose(e) {
    var that = this;
    var index = e.currentTarget.dataset.index;
    var select = this.data.select;
    if (select[index].index != 1) {
      select[index].index = 1
    } else {
      select[index].index = 0
    }
    that.setData({
      select: select
    })
  },
  customize(e) {
    var that = this;
    that.setData({
      customize: e.detail.value
    })
  },
  showModel(e) {
    var that = this;
    that.setData({
      Model: true,
      customize: ''
    })
  },
  activeBtn() {
    var that = this;
    var list = that.data.list;
    var stage = that.data.list.stage;
    if (stage < 5) {
      stage += 1
    }
    // var btnText = '下一步';
    var show = that.data.show;
    var data = {
      stage: stage
    }
    if (list.stage == 5) {
      if (that.data.type != 4) {
        that.sign();
      } else {
        wx.showToast({
          title: '跟单完成',
          icon: 'none'
        })
      }
    } else {
      that.gdzt(data);
    }
    that.setData({
      show: show
    })
  },
  dialonClose(){
    this.setData({
      dial:false
    })
  },
  phoneCall(e) {
    wx.makePhoneCall({
      phoneNumber: this.data.user.phone
    })
  },
  gdzt(data) {
    var that = this;
    var step_list = that.data.step_list;
    switch (Number(that.data.type)) {
      case 1:
        getApp().ports.fpgdzt({
          data: data,
          id: that.data.list.id
        }).then((res) => {
          var res = res.data;
          that.user(res.marketer)
          res.time = app.timeFormat(res.createTime, true)
          step_list[0].time = app.timeFormat(res.createTime, false, true)
          step_list[1].time = app.timeFormat(res.getDemandTime, false, true)
          step_list[2].time = app.timeFormat(res.olInviteTime, false, true)
          step_list[3].time = app.timeFormat(res.interviewTime, false, true)
          step_list[4].time = app.timeFormat(res.beforeSignTime, false, true)
          if (res.stage == 2) {
            that.setData({
              historyShow: true
            })
          }
          if(res.stage == 3){
            wx.setClipboardData({
              data: that.data.user.phone,
              success: function (res) {
                wx.getClipboardData({
                  success: function (res) {
                    wx.showToast({
                      title: '复制手机号码成功',
                      icon:'none'
                    })
                  }
                })
              }
            })
          }
          if(res.stage == 4){
            that.setData({
              dial:true
            })
          }
          that.setData({
            list: res,
            step_list: step_list
          })
        }).catch(() => {
          console.error('出啥错了？');
        });
        break;
      case 2:
        getApp().ports.zkgdzt({
          data: data,
          id: that.data.list.id
        }).then((res) => {
          var res = res.data;
          that.user(res.marketer)
          if (res.stage == 2) {
            that.setData({
              historyShow: true
            })
          }
          if(res.stage == 3){
            wx.setClipboardData({
              data: that.data.user.phone,
              success: function (res) {
                wx.getClipboardData({
                  success: function (res) {
                    wx.showToast({
                      title: '复制手机号码成功',
                      icon:'none'
                    })
                  }
                })
              }
            })
          }
          if(res.stage == 4){
            that.setData({
              dial:true
            })
          }
          res.time = app.timeFormat(res.createTime, true);
          step_list[0].time = app.timeFormat(res.createTime, false, true)
          step_list[1].time = app.timeFormat(res.getDemandTime, false, true)
          step_list[2].time = app.timeFormat(res.olInviteTime, false, true)
          step_list[3].time = app.timeFormat(res.interviewTime, false, true)
          step_list[4].time = app.timeFormat(res.beforeSignTime, false, true)

          if (res.discountHouseBookingorder.discountHouse.tagsstr) {
            let tags = [];
            res.discountHouseBookingorder.discountHouse.tagsstr.split(",").forEach(item => {
              tags.push({name: item})
            })
            res.tags = tags;
          }
          
          that.setData({
            list: res,
            step_list: step_list
          })
        }).catch(() => {
          console.error('出啥错了？');
        });
        break;
      case 4:
        getApp().ports.jdgdzt({
          data: data,
          id: that.data.list.id
        }).then((res) => {
          var res = res.data;
          that.user(res.marketer)
          if (res.stage == 2) {
            that.setData({
              historyShow: true
            })
          }
          if(res.stage == 3){
            wx.setClipboardData({
              data: that.data.user.phone,
              success: function (res) {
                wx.getClipboardData({
                  success: function (res) {
                    wx.showToast({
                      title: '复制手机号码成功',
                      icon:'none'
                    })
                  }
                })
              }
            })
          }
          if(res.stage == 4){
            that.setData({
              dial:true
            })
          }
          res.time = app.timeFormat(res.createTime, true);
          step_list[0].time = app.timeFormat(res.createTime, false, true)
          step_list[1].time = app.timeFormat(res.getDemandTime, false, true)
          step_list[2].time = app.timeFormat(res.olInviteTime, false, true)
          step_list[3].time = app.timeFormat(res.interviewTime, false, true)
          step_list[4].time = app.timeFormat(res.finishTime, false, true)

          res.tags = [{
            name: res.investigationOrder.foreclosedHouse.builtUpAreaSquareCentimeter + '㎡'
          }, {
            name: res.investigationOrder.rate + '折'
          }, {
            name: res.investigationOrder.foreclosedHouse.status
          }]
          that.setData({
            list: res,
            step_list: step_list
          })
          console.log(res)
        }).catch(() => {
          console.error('出啥错了？');
        });
        break;
    }
  },
  CloseHide() {
    this.setData({
      CloseShow: false
    });
  },
  sign() {
    var that = this;
    var data = {
      client: that.data.client
    };
    var obj = {
      finished: 1
    }
    wx.showModal({
      title: '即将发起签约订单',
      content: '请确保用户已准备好签约信息',
      success(res) {
        if (res.confirm) {
          var api = ['', 'fpljqy', 'zkljqy'];
          var typeId = ['', 'foreclosedHouseId', 'discountHouseId'];
          var type = [1, 2]
          data[typeId[Number(that.data.type)]] = that.data.typeId;
          if (type.includes(Number(that.data.type))) {
            getApp().ports[api[Number(that.data.type)]]({
              data: data
            }).then((res) => {
              var res = res.data;
              console.log(res, '成功');
              let url;
              switch (Number(that.data.type)) {
                case 1:
                  url = '../../subpackages/pages/fpsign/fpsign?status=1&id=' + res.id
                  break;
                case 2:
                  url = '../../subpackages/pages/discount/discount?status=2&id=' + res.id
                  break;
              }
              console.log(url)
              wx.navigateTo({
                url: url,
              })
              that.yyxg(obj);
              that.setData({
                btnText: '订单待评价'
              })
            }).catch(res => {
              console.error('出啥错了？');
            })
          }
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  onClickShow() {
    this.setData({
      show: true
    });
  },

  onClickHide() {
    this.setData({
      historyShow: false
    });
  },

  noop() {},
  onChange(event) {
    this.setData({
      value: event.detail,
    });
  },
  getUserInfo(event) {
    var that = this;
    var select = that.data.select;
    select.push({
      name: that.data.customize,
      index: 0
    });
    this.setData({
      Model: false,
      select: select
    });
  },

  onClose() {
    this.setData({
      Model: false
    });
  },
  navTo: function (e) { //跳转
    var url = e.currentTarget.dataset.url;
    console.log(url)
    wx.navigateTo({
      url: url
    })
  },
  yyxg(data) {
    var that = this;
    var api = ['', 'fpyyxg', 'zkyyxg'];
    var type = [1, 2]
    if (type.includes(Number(that.data.type))) {
      console.log(data)
      getApp().ports[api[Number(that.data.type)]]({
        data: data,
        id: that.data.id || that.data.list.id
      }).then((res) => {
        var res = res.data;
        console.log(res, '成功');
      }).catch(res => {
        console.error('出啥错了？');
      })
    }
  },
})